VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form DLGimport 
   BackColor       =   &H00E0E0E0&
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Import"
   ClientHeight    =   3240
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   3705
   BeginProperty Font 
      Name            =   "Verdana"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "DLGimport.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   216
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   247
   ShowInTaskbar   =   0   'False
   StartUpPosition =   1  'CenterOwner
   Begin MSComctlLib.ProgressBar ProgressBar 
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   2160
      Visible         =   0   'False
      Width           =   3495
      _ExtentX        =   6165
      _ExtentY        =   450
      _Version        =   393216
      Appearance      =   1
      Scrolling       =   1
   End
   Begin VB.CommandButton CMDcancel 
      Caption         =   "Cancel"
      Height          =   375
      Left            =   2400
      TabIndex        =   6
      Top             =   2760
      Width           =   1215
   End
   Begin VB.CommandButton CMDbrowse 
      Caption         =   "Browse"
      Default         =   -1  'True
      Height          =   375
      Left            =   2400
      TabIndex        =   0
      Top             =   720
      Width           =   1215
   End
   Begin VB.TextBox TXTimportFrom 
      Height          =   285
      Left            =   120
      TabIndex        =   4
      Top             =   360
      Width           =   3495
   End
   Begin VB.CommandButton CMDimport 
      Caption         =   "Import"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1080
      TabIndex        =   2
      Top             =   2760
      Width           =   1215
   End
   Begin VB.ComboBox LISTworksheets 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   177
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      ItemData        =   "DLGimport.frx":0442
      Left            =   120
      List            =   "DLGimport.frx":0444
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   1560
      Width           =   3495
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "Worksheet to import :"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   5
      Top             =   1320
      Width           =   2535
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Import From :"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   3
      Top             =   120
      Width           =   1455
   End
End
Attribute VB_Name = "DLGimport"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private _
    oExcel As Excel.Application, _
    oWorkbook As Excel.Workbook, _
    oWorkSheet As Excel.Worksheet

Private sFilePath As String

' Initialize the form, open the selected Excel file, and load the worksheet names into the list box ----------------------------------------------------

Public Sub init(sFilePath As String)

    On Error Resume Next
    
    Set oExcel = New Excel.Application
    
    If Err.Number <> 0 Then
    
        logMessage _
            1, _
            "DLGimport", _
            "Could not create new Excel application", _
            , _
            Err.Number, _
            Err.Description
    
    Else
    
        logMessage _
            5, _
            "DLGimport", _
            "Created new Excel object"

    End If
    
    On Error Resume Next
    
    Set oWorkbook = oExcel.Workbooks.Open(sFilePath)
     
    If Err.Number <> 0 Then
    
        logMessage _
            1, _
            "DLGimport", _
            "Could not open workbook for importing from Excel", _
            "File path = " & sFilePath, _
            Err.Number, _
            Err.Description
    
    Else
    
        logMessage _
            3, _
            "DLGimport", _
            "Opened workbook for importing from Excel", _
            "File path = " & sFilePath

    End If
     
    LISTworksheets.Clear
     
    For Each oWorkSheet In oWorkbook.Worksheets
    
         LISTworksheets.AddItem oWorkSheet.Name
    
    Next
    
    LISTworksheets.ListIndex = 0
    
    Me.TXTimportFrom.Text = sFilePath
    
    Me.Show vbModal, FRMmain

End Sub

' Events ----------------------------------------------------------------------------------------------------------------------

Private Sub CMDbrowse_Click()

    On Error Resume Next
    
    Unload Me
    
    FRMmain.fileImport_Click

End Sub


Private Sub CMDcancel_Click()

    On Error Resume Next

    oExcel.Quit
    
    Unload Me

End Sub

Private Sub CMDimport_Click()

    On Error Resume Next
    
    MODimport.importFromExcel oWorkbook, LISTworksheets.ListIndex

End Sub
